package com.epfresh.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.epfresh.R;
import com.epfresh.adapter.OrderAdapter;
import com.epfresh.api.adapter.CommonAdapter;
import com.epfresh.api.adapter.ViewHolder;
import com.epfresh.api.constant.AppPurchaseRouterConstant;
import com.epfresh.api.entity.RequestEntityPurchase;
import com.epfresh.api.entity.RequestTag;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.entity.StatusEntity;
import com.epfresh.api.entity.TagPager;
import com.epfresh.api.helper.ApplicationHelper;
import com.epfresh.api.http.HttpRequest;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.api.utils.T;
import com.epfresh.api.widget.list.LoadMoreListView;
import com.epfresh.api.widget.ptr.PtrDefaultHandler;
import com.epfresh.api.widget.ptr.PtrFrameLayout;
import com.epfresh.api.widget.ptr.PtrHandler;
import com.epfresh.basedialog.CustomDialog;
import com.epfresh.bean.ContentEntity;
import com.epfresh.bean.OrderListBean;
import com.epfresh.constant.Constant;
import com.epfresh.global.BaseActivity;
import com.epfresh.global.DataManager;
import com.epfresh.wxapi.WXPayEntryActivity;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderSearchActivity extends BaseActivity implements LoadMoreListView.IXListViewListener{

	static final String TAG = "OrderSearchActivity";
	ImageView ivBack;
	ImageView ivSearch;
	EditText etContent;
	TextView tvSearch;

	ImageView ivDelete;
	View rlHistory,rlContent;

	ListView lvHistory;
	LoadMoreListView lvContent;

	SharedPreferences sharedPreferences;
	SharedPreferences.Editor editor;
	List<String> historyList = new ArrayList<String>();
	StringAdapter historyAdapter;
	String historyTogether;
	ArrayList<OrderListBean> list;
	OrderAdapter adapter;
	protected View mainView;
	protected View vException;
	protected TextView tvExceptionDescription;
	protected ImageView ivExceptionIcon;
	private ProgressBar pb;
	private int requestSucceedCount = 0;
	private int PAGE_SIZE = 10;


	private TagPager tagPager = new TagPager();
	public int type=1;

	Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context = mContext;
		initShare();
		initView();
		//loadData(tagPager.getNumber());
	}
	private void initView() {
		setContentView(R.layout.activity_order_search);
/*		View cart = findViewById(R.id.v_cart_bg);
		View bottom = findViewById(R.id.rl_bottom);
		cart.setVisibility(View.GONE);
		bottom.setVisibility(View.GONE);*/
		rlContent = findViewById(R.id.rl_content);
		rlHistory = findViewById(R.id.rl_history);
		lvHistory = (ListView)findViewById(R.id.lv_history);
		lvContent = (LoadMoreListView)findViewById(R.id.lv_content);

		Log.i("initView", historyTogether + "——————————————————————————————————");//
		historyAdapter = new StringAdapter(this,historyList,R.layout.item_string);
		initHistory();
		lvHistory.setAdapter(historyAdapter);
		ivBack = (ImageView) findViewById(R.id.iv_back);
		etContent = (EditText)findViewById(R.id.et_content);
		tvSearch = (TextView)findViewById(R.id.tv_search);
		tvSearch.setOnClickListener(this);
		ivDelete = (ImageView)findViewById(R.id.iv_delete);
		ivDelete.setOnClickListener(this);
		ivBack.setOnClickListener(this);

		//vException = findViewById(R.id.v_exception);
		mainView = findViewById(R.id.fragment_ptr_home_ptr_frame);
		initHeadView();
		tagPager.setNumber(0);
		// initContentList(type);
		list = new ArrayList<>();
		adapter = new OrderAdapter(mContext,lvContent, list);
		adapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> adapterView, View v, int position, long l) {

// 交货码，查看物流，取消订单，确认收货，支付， 详情
				switch (v.getId()) {
					case R.id.tv_code:
						showCodeDialog(list.get(position).getInspectCode());
						break;
					case R.id.tv_sure:
						if(isWindowLocked())
							return;
						else
							mHttpCheck(position);
						break;
					case R.id.tv_logistics:
						Intent h5IntentTrace = new Intent(context,WebActivity.class);
						h5IntentTrace.putExtra(Constant.KEY_WEB_URL, com.epfresh.api.constant.Constant.URL_ORDER_TRACE + "orderId=" + list.get(position).getOrderId());
						h5IntentTrace.putExtra(Constant.KEY_WEB_TITLE,"");
						startActivity(h5IntentTrace);
//						Intent logisticsInfo = new Intent(context, OrderLogisticsInfoActivity.class);
//						logisticsInfo.putExtra("logisticsNo", list.get(position).getOrderId());
//						context.startActivity(logisticsInfo);
						break;
					case R.id.tv_pay:
						if(isWindowLocked())
							return;
						else {
							if (list.get(position).getButtonType() == 1) {
								Intent pay = new Intent(context, WXPayEntryActivity.class);
								pay.putExtra("payWay", 1);
								String orderId = list.get(position).getOrderId();
								pay.putExtra("orderId", orderId);
								context.startActivity(pay);
							} else {
								mHttpCheck(position);
							}
						}
						break;
					case R.id.tv_cancel:
						flagPosition = position;
						showCancelDialog();
						break;
					case R.id.tv_more:
						if(isWindowLocked())
							return;
						else
							mHttpMore(position);
						break;
					case R.id.tv_evaluate:
						Intent h5Intent = new Intent(context, WebActivity.class);
						h5Intent.putExtra(Constant.KEY_WEB_URL, com.epfresh.api.constant.Constant.URL_ORDER_COMMENT +
								"orderId=" + list.get(position).getOrderId() +
								"&accountId=" + ApplicationHelper.getInstance().getUser().getAccountId());
						h5Intent.putExtra(Constant.KEY_WEB_TITLE, "评价");
						startActivity(h5Intent);
//						Intent evaluate = new Intent(context, CommentNewActivity.class);
//						evaluate.putExtra("orderId",list.get(position).getOrderId());
//						startActivityForResultCommon(evaluate,0x001);
						break;
					case R.id.ll_order:
					case R.id.rl_more:
					case R.id.ll_images:
						Intent detail = new Intent(context,H5OrderDetailActivity.class);
						detail.putExtra("orderId", list.get(position).getOrderId());
						detail.putExtra(Constant.KEY_WEB_URL, "http://m.epfresh.com/help/order_detail.html?orderId="+list.get(position).getOrderId());
						detail.putExtra(Constant.KEY_WEB_TITLE, "订单详情");
						detail.putExtra("page",0);
						startActivityForResultCommon(detail,0x001);
/*						Intent detail = new Intent(context,H5AllGoods.class);
						detail.putExtra("orderId", list.get(position).getOrderId());
						detail.putExtra(Constant.KEY_WEB_URL, "http://m.epfresh.com/help/order_detail.html?orderId="+list.get(position).getOrderId());
						detail.putExtra(Constant.KEY_WEB_TITLE, "订单详情");
						detail.putExtra("page",0);
						startActivityForResultCommon(detail,0x001);*/
						break;
				}
			}
		});


		lvContent.setXListViewListener(this);
		lvContent.setAdapter(adapter);
		View rlNoDate = findViewById(R.id.rl_nodate);
		lvContent.setEmptyView(rlNoDate);

		etContent.setOnEditorActionListener(new TextView.OnEditorActionListener() {

			@Override
			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

				if (actionId == EditorInfo.IME_ACTION_SEARCH) {

					if (TextUtils.isEmpty(etContent.getText().toString())) {
						return true;
					}
					tagPager.setNumber(0);
					lvContent.resetNoMore();
					requestSucceedCount = 0;
					rlHistory.setVisibility(View.GONE);
					rlContent.setVisibility(View.VISIBLE);
					loadData(0);
					editor.putString("order_history", sharedPreferences.getString("order_history", "") + "," + etContent.getText().toString());
					editor.commit();
					return true;
				}
				return false;
			}
		});
	}

	private void initHeadView() {
		ptrFrameLayout = (PtrFrameLayout) findViewById(R.id.fragment_ptr_home_ptr_frame);
		ptrFrameLayout.setPtrHandler(ptrHandler);
	}

	private PtrFrameLayout ptrFrameLayout;
	private PtrHandler ptrHandler = new PtrHandler() {
		@Override
		public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
			return PtrDefaultHandler.checkContentCanBePulledDown(frame, lvContent, header);
		}

		@Override
		public void onRefreshBegin(PtrFrameLayout frame) {
			refresh();
		}
	};
	boolean refreshFlag = false;

	public void refresh() {
		lvContent.resetNoMore();
		refreshFlag = true;
		loadData(0);
	}


	@Override
	public void onLoadMore() {
		int number = tagPager.getNumber();
		loadData(number + 1);
		//initContentList(number + 1);
	}

	public void updateViewStatus(RequestTag requestTag) {
		ptrFrameLayout.refreshComplete();
		if (tagPager.isLast()) {
			lvContent.noMore();
		} else {
			lvContent.stopLoadMore();
		}
	}





	void loadData(int page){
		RequestEntityPurchase<Map<String, String>> entity = new RequestEntityPurchase<>();
		Map<String, String> map = new HashMap<>();
		map.put("accountId", getUser().getAccountId());
		if(TextUtils.isEmpty(etContent.getText()))
			return;
		map.put("key", etContent.getText().toString());
		map.put("pageNumber", page + "");
		map.put("pageSize", PAGE_SIZE + "");
		map.put("sortProperty", "placeOrderTime");
		map.put("sortDirection", "DESC");
		entity.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_order_search);
		entity.setParameters(map);
		RequestTag requestTag = new RequestTag();
		requestTag.tag = com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_order_search;
		requestTag.action = page;
		requestTag.type = RequestTag.TYPE_CURRENT;
		request(entity, requestTag, onRequestListener);
	}
	OnRequestListener<ContentEntity<OrderListBean>> onRequestListener = new OnRequestListener<ContentEntity<OrderListBean>>() {
		@Override
		public ContentEntity<OrderListBean> jsonToObj(String responseStr) {
			return new Gson().fromJson(responseStr, new TypeToken<ContentEntity<OrderListBean>>() {
			}.getType());
		}

		@Override
		public void onFail(int failCode, Object arg, Object tag) {
			hideProgressDialog();
			RequestTag requestTag = (RequestTag) tag;
			updateViewStatus(requestTag);
			if (requestSucceedCount == 0){
				showExceptionView(R.mipmap.order_no, "网络问题,请点击重试", HttpRequest.FAIL_NET_FAULT);
			}
		}

		@Override
		public void onResponseError(int failCode, Object arg, Object tag) {
			hideProgressDialog();

			if (requestSucceedCount == 0){
				showExceptionView(R.mipmap.order_no, arg + "", HttpRequest.FAIL_DATA_FAULT);//arg + ",请点击重试"
			}
			RequestTag requestTag = (RequestTag) tag;
			updateViewStatus(requestTag);
		}

		@Override
		public void onStart(Object tag) {
			if (requestSucceedCount == 0){
				showProgressView();
			}
		}

		@Override
		public void onResponse(ResponseEntity<ContentEntity<OrderListBean>> response, Object tag) {
			//页面第一次调用网络请求接口并成功
			hideProgressDialog();
			showMainView();
			requestSucceedCount ++;
			RequestTag requestTag = (RequestTag) tag;
			if (requestTag.action == 0) {
				list.clear();
			}
			ContentEntity<OrderListBean> orderResponse = response.getResponseElement();
			List<OrderListBean> content = orderResponse.getContent();
			tagPager.setLast(orderResponse.getLast());
			tagPager.setNumber(orderResponse.getNumber());
			tagPager.setSize(orderResponse.getSize());
			tagPager.setTotalElements(orderResponse.getTotalElements());
			list.addAll(content);
			adapter.notifyDataSetChanged();

			if(orderResponse.getNumber()==0){
				if(refreshFlag) {
					lvContent.setSelection(0);
					refreshFlag=false;
				}
			}
			updateViewStatus(requestTag);

		}
	};

	void initShare(){
		sharedPreferences = getSharedPreferences("search_history", Context.MODE_PRIVATE); //私有数据
		editor = sharedPreferences.edit();//获取编辑器
	}
	void initHistory(){
		historyTogether = sharedPreferences.getString("order_history","");
		Log.i("historyTogether",historyTogether+"——————————————————————————————————");
		historyList.clear();
		if(!historyTogether.equals("")){
			ArrayList<String> flag = new ArrayList<>();
			flag.addAll(Arrays.asList(historyTogether.split(",")));
			for(int i=flag.size()-1;i>0;i--){
				if(!historyList.contains(flag.get(i)))
					historyList.add(flag.get(i));
				if(historyList.size()==10)
					break;
			}
		}
		historyAdapter.notifyDataSetChanged();
	}
	protected View getToolBar() {
		View actionbar = this.inflaterView(R.layout.toolbar_search, (ViewGroup)null);
		((EditText)actionbar.findViewById(R.id.et_content)).setHint("请输入订单号、商品标题");//("请输入收货人姓名、手机号、订单号");
		RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(-1, this.getResources().getDimensionPixelSize(com.epfresh.api.R.dimen.action_bar_height));
		actionbar.setLayoutParams(lp);
		return actionbar;
	}
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.iv_back:
				// 返回上一页
				finish();
				break;
			case R.id.tv_search:
				if (TextUtils.isEmpty(etContent.getText().toString())){
					return;
				}
				tagPager.setNumber(0);
				lvContent.resetNoMore();
				requestSucceedCount = 0;
				rlHistory.setVisibility(View.GONE);
				rlContent.setVisibility(View.VISIBLE);
				//refresh();
				loadData(0);
				editor.putString("order_history", sharedPreferences.getString("order_history", "") + "," + etContent.getText().toString());
				editor.commit();
				break;
			case R.id.iv_delete:
				CustomDialog.Builder builder = new CustomDialog.Builder(mContext);
				builder.setMessage("确定要删除历史搜索吗？");//设置显示的内容
				//builder.setTitle("提示");
				builder.setTitleVisible(false);
				builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {//添加确定按钮
					@Override
					public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
						// mHttpSure();
						editor.putString("order_history", "");
						editor.commit();
						Log.i("iv_delete", historyTogether + "——————————————————————————————————");
						initHistory();
						dialog.dismiss();
					}
				});
				builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {//添加返回按钮
					@Override
					public void onClick(DialogInterface dialog, int which) {//响应事件
						dialog.dismiss();
					}

				});
				builder.create().show();
				break;
			case R.id.tv_order_not_want:
				dialog.dismiss();
				if(list==null||list.size()==0){
					T.toast("请刷新当前页面");
					return;
				}
				if(isWindowLocked())
					return;
				else
					mHttpCancel(list.get(flagPosition).getOrderId(),"不想要了");
				break;
			case R.id.tv_order_wrong:
				dialog.dismiss();
				if(list==null||list.size()==0){
					T.toast("请刷新当前页面");
					return;
				}
				if(isWindowLocked())
					return;
				else
					mHttpCancel(list.get(flagPosition).getOrderId(),"点错了");
				break;
			case R.id.v_order_cancel:
				dialog.dismiss();
				break;


			default:
				break;
		}
	}

	class StringAdapter extends CommonAdapter<String>{
		public StringAdapter(Context context, List<String> historyList, int a) {
			super(context, historyList, a);
		}

		@Override
		public void convert(ViewHolder holder, final String bean) {
			holder.setText(R.id.tv_string, bean);
			holder.setOnClickListener(R.id.tv_string, new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					etContent.setText(bean);
					etContent.setSelection(bean.length());
					tvSearch.performClick();
				}
			});
		}
	}


	private Dialog dialogCancel;
	TextView[] numbers = new TextView[6];
	void showCodeDialog(String code){
		if (dialogCancel == null) {
			View view = LayoutInflater.from(context).inflate(R.layout.dialog_code, null);
			dialogCancel = new Dialog(context, R.style.ActionSheetDialogStyle);
			dialogCancel.setContentView(view);
			Window dialogWindow = dialogCancel.getWindow();
			if(dialogWindow==null)
				return;
			dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
			WindowManager.LayoutParams lp = dialogWindow.getAttributes();
			lp.width = LocalDisplay.SCREEN_WIDTH_PIXELS;
			dialogWindow.setAttributes(lp);
			numbers[0] = (TextView)view.findViewById(R.id.number1);
			numbers[1] = (TextView)view.findViewById(R.id.number2);
			numbers[2] = (TextView)view.findViewById(R.id.number3);
			numbers[3] = (TextView)view.findViewById(R.id.number4);
			numbers[4] = (TextView)view.findViewById(R.id.number5);
			numbers[5] = (TextView)view.findViewById(R.id.number6);
		}
		for(int i=0;i<6;i++){
			numbers[i].setText(""+code.charAt(i));
		}
		dialogCancel.show();
	}

	private Dialog dialog;
	private int flagPosition;
	View view,v_order_cancel,tv_order_not_want,tv_order_wrong;
	public void showCancelDialog() {
		if (dialog == null) {
			view = LayoutInflater.from(context).inflate(R.layout.dialog_order, null);
			v_order_cancel = view.findViewById(R.id.v_order_cancel);
			tv_order_not_want = view.findViewById(R.id.tv_order_not_want);
			tv_order_wrong = view.findViewById(R.id.tv_order_wrong);
			v_order_cancel.setOnClickListener(this);
			tv_order_wrong.setOnClickListener(this);
			tv_order_not_want.setOnClickListener(this);
			dialog = new Dialog(context, R.style.no_title_dialog);
			dialog.setContentView(view);
			Window dialogWindow = dialog.getWindow();
			if(dialogWindow==null)
				return;
			dialogWindow.setGravity(Gravity.CENTER);
			WindowManager.LayoutParams lp = dialogWindow.getAttributes();
			lp.width = LocalDisplay.SCREEN_WIDTH_PIXELS - LocalDisplay.dp2px(30);
			dialogWindow.setAttributes(lp);
		}
		tv_order_wrong.setTag(R.id.item_key_position, flagPosition);
		v_order_cancel.setTag(R.id.item_key_position, flagPosition);
		tv_order_not_want.setTag(R.id.item_key_position, flagPosition);
		dialog.show();
	}
	/** 取消订单 */
	private void mHttpCancel(String  id,String reason) {
		Log.i("列表测试", "" + id + reason);
		RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
		data.setCmd(AppPurchaseRouterConstant.cmd_order_order_cancel);
		Map<String, Object> map = new HashMap<>();
		map.put("orderId", id);
		map.put("reason", reason);
		data.setParameters(map);
		((BaseActivity)context).request(data, AppPurchaseRouterConstant.cmd_order_order_cancel, new OnRequestListener<StatusEntity>() {
			@Override
			public StatusEntity jsonToObj(String responseStr) {
				return new Gson().fromJson(responseStr, StatusEntity.class);
			}

			@Override
			public void onFail(int failCode, Object arg, Object tag) {
				Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onResponseError(int failCode, Object arg, Object tag) {
				((BaseActivity) context).toast((arg == null ? "" : arg + ""));
			}

			@Override
			public void onStart(Object tag) {
			}

			@Override
			public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
				StatusEntity responseElement = response.getResponseElement();
				if (responseElement.isSuccess()) {
					//requestOrderInfo();
/*                    if(type==0) {
                        OrderAdapter.this.list.get(flagPosition).setButtonType(11);
                        OrderAdapter.this.list.get(flagPosition).setPurchaseStatusTitle("交易关闭");
                    }else{
                        OrderAdapter.this.list.remove(flagPosition);
                    }
                    notifyDataSetChanged();*/
					intoFresh();
					T.toast("已取消");
				} else {
					T.toast("服务器出现小问题，请稍后再试");
				}
			}
		});
	}

	public void intoFresh(){
		showProgressView();
		refresh();
	}
	public void startActivityForResultCommon(Intent intent, int requestCode){
		startActivityForResult(intent, requestCode);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK && requestCode == 0x001) {
			intoFresh();
		}
	}

	/** 确认收货1 有无尾款 */
	class SureCheckBean {
		int type;
		double money;
	}
	private void mHttpCheck(final int id) {
		RequestEntityPurchase<Map<String, Object>> dataRequest = new RequestEntityPurchase<>();
		dataRequest.setCmd(AppPurchaseRouterConstant.cmd_order_order_checkReceiveGood);

		Map<String, Object> map = new HashMap<>();
		map.put("orderId", this.list.get(id).getOrderId());
		dataRequest.setParameters(map);
		((BaseActivity)context).request(dataRequest, AppPurchaseRouterConstant.cmd_order_order_checkReceiveGood, new OnRequestListener<SureCheckBean>() {
			@Override
			public SureCheckBean jsonToObj(String responseStr) {
				return new Gson().fromJson(responseStr, SureCheckBean.class);
			}

			@Override
			public void onFail(int failCode, Object arg, Object tag) {
				((BaseActivity) context).hideProgressDialog();
				Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onResponseError(int failCode, Object arg, Object tag) {
				((BaseActivity) context).hideProgressDialog();
				T.toast((arg == null ? "" : arg + ""));
			}

			@Override
			public void onStart(Object tag) {
				((BaseActivity) context).showProgressDialog();
			}

			@Override
			public void onResponse(ResponseEntity<SureCheckBean> response, Object tag) {
				((BaseActivity) context).hideProgressDialog();
				final SureCheckBean responseElement = response.getResponseElement();
				android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
				builder.setMessage("本订单已支付，请收到货后再点击“确认收货”！");//设置显示的内容
				if (responseElement.type == 1||responseElement.type == 2) {//0结束；1：收银台，2：有尾款
					//builder.setMessage("您已经收到货物，验货通过，清点无误！" + "\n" + "去收银台付款：" + responseElement.money + "元。");
					builder.setMessage("您还有未支付钱款，去支付？");
				}/* else if (responseElement.type == 2) {
                    builder.setMessage("您已经收到货物，验货通过，清点无误！" + "\n" + "并且已经付清尾款：" + responseElement.money + "元。");
                }*/
				builder.setTitle("")
						.setPositiveButton("确定", new DialogInterface.OnClickListener() {//添加确定按钮
							@Override
							public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
								if(responseElement.type==1||responseElement.type==2){
									Intent pay = new Intent(context, WXPayEntryActivity.class);
									pay.putExtra("orderId",list.get(id).getOrderId());
									pay.putExtra("type","2");
									context.startActivity(pay);
									return;
								}else{
									mHttpSure(id, responseElement.type);
									return;
								}
							}
						}).setNegativeButton("取消", new DialogInterface.OnClickListener() {//添加返回按钮
					@Override
					public void onClick(DialogInterface dialog, int which) {//响应事件
						// TODO Auto-generated method stub
					}

				}).show();//在按键响应事件中显示此对话框

			}
		});
	}
	/** 确认收货2 */
	private void mHttpSure(int id,int type1) {
		RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
		data.setCmd(AppPurchaseRouterConstant.cmd_order_order_confirmReceiveGood);
		Map<String, Object> map = new HashMap<>();
		map.put("orderId", this.list.get(id).getOrderId());
		map.put("type", ""+type1);
		data.setParameters(map);
		((BaseActivity)context).request(data, AppPurchaseRouterConstant.cmd_order_order_confirmReceiveGood, new OnRequestListener<StatusEntity>() {
			@Override
			public StatusEntity jsonToObj(String responseStr) {
				return new Gson().fromJson(responseStr, StatusEntity.class);
			}

			@Override
			public void onFail(int failCode, Object arg, Object tag) {
				Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onResponseError(int failCode, Object arg, Object tag) {
				T.toast((arg == null ? "" : arg + ""));
			}

			@Override
			public void onStart(Object tag) {
			}

			@Override
			public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
				StatusEntity responseElement = response.getResponseElement();
				if (responseElement.isSuccess()) {
					intoFresh();
				} else {
					T.toast("服务器出现小问题，请稍后再试");
				}
			}
		});
	}

	/** 再来一单 */
	private void mHttpMore(int id) {
		RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
		data.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_again);
		Map<String, Object> map = new HashMap<>();
		map.put("orderId", list.get(id).getOrderId());
		map.put("accountId", ApplicationHelper.getInstance().getUser().getAccountId());
		map.put("cityId", ApplicationHelper.getInstance().getCity().getCityId());
		data.setParameters(map);
		((BaseActivity)context).request(data, com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_again, new OnRequestListener<StatusEntity>() {
			@Override
			public StatusEntity jsonToObj(String responseStr) {
				return new Gson().fromJson(responseStr, StatusEntity.class);
			}

			@Override
			public void onFail(int failCode, Object arg, Object tag) {
				((BaseActivity) context).hideProgressDialog();
				//Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onResponseError(int failCode, Object arg, Object tag) {
				((BaseActivity) context).hideProgressDialog();
				//T.toast((arg == null ? "" : arg + ""));
			}

			@Override
			public void onStart(Object tag) {
				((BaseActivity) context).showProgressDialog();
			}

			@Override
			public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
				((BaseActivity) context).hideProgressDialog();
				Intent intent = new Intent(context,
						HomeActivity.class);
				intent.putExtra("home_tab_index", 1);
				DataManager.getInstance().isNeedRefreshCart = true;
				context.startActivity(intent);
				adapter.notifyDataSetChanged();
			}
		});
	}
	long mLastOnClickTime;
	public boolean isWindowLocked() {
		long current = SystemClock.elapsedRealtime();
		if(current - this.mLastOnClickTime > 1500L) {
			this.mLastOnClickTime = current;
			return false;
		} else {
			return true;
		}
	}



/*
	class OrderAdapter extends BaseAdapter implements View.OnClickListener {

		public ListView lv;
		public Context context;
		public List<OrderListBean> list;
		public int type=1;

		public OrderAdapter(Context context, ListView lv, List<OrderListBean> groupList, int type) {
			this.context = context;
			this.list = groupList;
			this.lv = lv;
			this.type = type;
			if(type==9){
				this.type = 4;
			}
		}

		@Override
		public int getCount() {
			return list != null ? list.size() : 0;
		}

		@Override
		public Object getItem(int position) {
			return position;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}


		@Override
		public View getView(int groupPosition, View convertView, ViewGroup parent) {
			ViewHolder vh = null;
			if (convertView == null) {
				vh = new ViewHolder();
				convertView = LayoutInflater.from(context).inflate(R.layout.item_list_order_more, null, false);
				vh.tv_order_id = (TextView) convertView.findViewById(R.id.tv_order_id);
				vh.tv_freight_end = (TextView) convertView.findViewById(R.id.tv_freight_end);

				vh.tv_market = (TextView) convertView.findViewById(R.id.tv_market);

				vh.tv_post_type = (TextView) convertView.findViewById(R.id.tv_post_type);
				vh.tv_place_time = (TextView) convertView.findViewById(R.id.tv_place_time);
				vh.iv_logo = (ImageView) convertView.findViewById(R.id.iv_logo);
				vh.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
				vh.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
				vh.iv_promotion = (ImageView) convertView.findViewById(R.id.iv_promotion);
				vh.ll_images = (LinearLayout) convertView.findViewById(R.id.ll_images);
				vh.scroll = convertView.findViewById(R.id.scroll);

				vh.rl_more = convertView.findViewById(R.id.rl_more);
				vh.rl_only_one = convertView.findViewById(R.id.rl_only_one);
				vh.tv_code = (TextView) convertView.findViewById(R.id.tv_code);
				vh.tv_logistics = (TextView) convertView.findViewById(R.id.tv_logistics);
				vh.tv_cancel = (TextView) convertView.findViewById(R.id.tv_cancel);
				vh.tv_sure = (TextView) convertView.findViewById(R.id.tv_sure);
				vh.tv_pay = (TextView) convertView.findViewById(R.id.tv_pay);
				vh.tv_evaluate = (TextView) convertView.findViewById(R.id.tv_evaluate);


				vh.tv_more = (TextView) convertView.findViewById(R.id.tv_more);

				vh.tv_total_kind = (TextView) convertView.findViewById(R.id.tv_total_kind);
				vh.tv_total_money = (TextView) convertView.findViewById(R.id.tv_total_money);
				vh.ll_order = convertView.findViewById(R.id.ll_order);


				convertView.setTag(vh);
			} else {
				vh = (ViewHolder) convertView.getTag();
			}
			vh.tv_pay.setTag(R.id.item_key_position, groupPosition);
			vh.tv_code.setTag(R.id.item_key_position, groupPosition);
			vh.tv_logistics.setTag(R.id.item_key_position, groupPosition);
			vh.tv_cancel.setTag(R.id.item_key_position, groupPosition);
			vh.tv_sure.setTag(R.id.item_key_position, groupPosition);
			vh.tv_evaluate.setTag(R.id.item_key_position, groupPosition);

			vh.tv_more.setTag(R.id.item_key_position, groupPosition);
			vh.ll_images.setTag(R.id.item_key_position, groupPosition);
			vh.ll_images.setOnClickListener(this);
			vh.ll_order.setTag(R.id.item_key_position, groupPosition);
			vh.ll_order.setOnClickListener(this);
			vh.scroll.setTag(R.id.item_key_position, groupPosition);
			vh.scroll.setOnClickListener(this);


			OrderListBean order = list.get(groupPosition);
			vh.tv_order_id.setText("订单："+order.getOrderNo());
			vh.tv_place_time.setText(order.getPlaceOrderTime());
			vh.tv_market.setText(order.getWholeSaleMarketTitle());
			vh.tv_post_type.setText(order.getPurchaseStatusTitle());////
			vh.tv_total_kind.setText("共"+order.getProductCount()+"件");
			vh.tv_total_money.setText("订单金额："+order.getOrderSumPrice()+"元");
			vh.tv_freight_end.setText("("+"含运费："+order.getProductExpressFee()+"元)");

			vh.tv_post_type.setTag(R.id.item_key_position, groupPosition);
			vh.tv_post_type.setOnClickListener(this);

			if(order.getResult().size()>1){
				vh.rl_more.setVisibility(View.VISIBLE);
				vh.rl_only_one.setVisibility(View.GONE);
				addImages(vh.ll_images,list.get(groupPosition));
			}else if(order.getResult().size()==1){
				vh.rl_more.setVisibility(View.GONE);
				vh.rl_only_one.setVisibility(View.VISIBLE);
				vh.tv_title.setText(*//*"        " + *//*order.getResult().get(0).getProductTitle());
*//*				if (1 == (order.getResult().get(0).getSalesType())) {//现售
					vh.tv_type.setText("现");
					vh.tv_type.setBackgroundResource(R.drawable.good_type_bg);
					vh.tv_type.setTextColor(Color.RED);

				} else if (2 == (order.getResult().get(0).getSalesType())) {//预售
					vh.tv_type.setText("预");
					vh.tv_type.setBackgroundResource(R.drawable.good_type_pre_bg);
					vh.tv_type.setTextColor(Color.parseColor("#43adea"));

				} else {
					vh.tv_type.setText("现");
					vh.tv_type.setBackgroundResource(R.drawable.good_type_bg);
					vh.tv_type.setTextColor(Color.RED);
				}*//*
				ImageLoader.getInstance().displayImage(order.getResult().get(0).getProductImgUrl(), vh.iv_logo);
				String promotionMarkUrl = order.getResult().get(0).getMarkUrl();
				ImageLoader.getInstance().displayImage(promotionMarkUrl, new ImageViewAware(vh.iv_promotion), BaseApplication.getTagOptions(promotionMarkUrl) , null, null, null);
			}

			initBottom(list.get(groupPosition).getButtonType(),vh);

			convertView.setTag(vh);
			convertView.setClickable(true);
			return convertView;
		}

		public class ViewHolder {
			TextView tv_freight_end;


			TextView tv_market;
			TextView tv_post_type;
			TextView tv_place_time;
			TextView tv_order_id;

			TextView tv_total_kind;
			TextView tv_total_money;

			ImageView iv_promotion;

			ImageView iv_logo;
			TextView tv_type;
			TextView tv_title;
			LinearLayout ll_images;
			View scroll;

			View rl_more,rl_only_one;

			View ll_order;

			TextView tv_code;
			TextView tv_logistics;
			TextView tv_cancel;
			TextView tv_sure;
			TextView tv_pay;
			TextView tv_evaluate;
			TextView tv_more;

		}


		void addImages(LinearLayout v, OrderListBean imagesList){
			v.removeAllViews();
			for(int i=0;i<imagesList.getResult().size();i++){
				ImageView flag = new ImageView(context);
				flag.setScaleType(ImageView.ScaleType.CENTER_CROP);
				LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LocalDisplay.dp2px(50),LocalDisplay.dp2px(50));
				flag.setLayoutParams(lp);
				LinearLayout.LayoutParams lpFrame = new LinearLayout.LayoutParams(LocalDisplay.dp2px(50),LocalDisplay.dp2px(50));
				ImageLoader.getInstance().displayImage(imagesList.getResult().get(i%imagesList.getResult().size()).getProductImgUrl(),flag);
				FrameLayout f = new FrameLayout(context);
				lpFrame.setMargins(LocalDisplay.dp2px(7), 0, LocalDisplay.dp2px(7), 0);
				if(i==0){
					lpFrame.setMargins(LocalDisplay.dp2px(10), 0, LocalDisplay.dp2px(7), 0);
				}
				if(i==imagesList.getResult().size()){
					lpFrame.setMargins(LocalDisplay.dp2px(7), 0, LocalDisplay.dp2px(10), 0);
				}
				f.setLayoutParams(lpFrame);
				f.addView(flag);
				ImageView tag = new ImageView(context);
				tag.setScaleType(ImageView.ScaleType.CENTER_CROP);
				LinearLayout.LayoutParams tagLp = new LinearLayout.LayoutParams(LocalDisplay.dp2px(30),LocalDisplay.dp2px(33));
				tag.setLayoutParams(tagLp);
				ImageLoader.getInstance().displayImage(imagesList.getResult().get(i%imagesList.getResult().size()).getMarkUrl(), new ImageViewAware(tag), BaseApplication.getTagOptions(imagesList.getResult().get(i%imagesList.getResult().size()).getMarkUrl()) , null, null, null);
				f.addView(tag);
				v.addView(f);
			}
			for(int i=0;i+imagesList.getResult().size()<5;i++){
				ImageView flag = new ImageView(context);
				flag.setScaleType(ImageView.ScaleType.CENTER_CROP);
				LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LocalDisplay.dp2px(50),LocalDisplay.dp2px(50));
				lp.setMargins(LocalDisplay.dp2px(7), 0, LocalDisplay.dp2px(7), 0);
				flag.setLayoutParams(lp);
				v.addView(flag);
			}
		}

		void initBottom(int type, ViewHolder vh){
			vh.tv_code.setOnClickListener(this);
			vh.tv_logistics.setOnClickListener(this);
			vh.tv_cancel.setOnClickListener(this);
			vh.tv_sure.setOnClickListener(this);
			vh.tv_pay.setOnClickListener(this);
			vh.tv_evaluate.setOnClickListener(this);
			vh.tv_more.setOnClickListener(this);

			vh.tv_code.setVisibility(View.GONE);
			vh.tv_logistics.setVisibility(View.GONE);
			vh.tv_cancel.setVisibility(View.GONE);
			vh.tv_sure.setVisibility(View.GONE);
			vh.tv_pay.setVisibility(View.GONE);
			vh.tv_evaluate.setVisibility(View.GONE);
			vh.tv_more.setVisibility(View.GONE);

			switch (type) {

				case 1://待付款
					vh.tv_logistics.setVisibility(View.VISIBLE);
					vh.tv_cancel.setVisibility(View.VISIBLE);
					vh.tv_pay.setVisibility(View.VISIBLE);
					break;
				case 2://待发货
					vh.tv_logistics.setVisibility(View.VISIBLE);
					vh.tv_cancel.setVisibility(View.VISIBLE);
					break;
				case 3://待收货
					vh.tv_code.setVisibility(View.VISIBLE);
					vh.tv_logistics.setVisibility(View.VISIBLE);
					vh.tv_sure.setVisibility(View.VISIBLE);
					break;
				case 4:
					//vh.tv_logistics.setVisibility(View.VISIBLE);
					//vh.tv_code.setVisibility(View.VISIBLE);
					vh.tv_evaluate.setVisibility(View.VISIBLE);
					vh.tv_more.setVisibility(View.VISIBLE);

					break;
				case 5://拒收
					vh.tv_logistics.setVisibility(View.VISIBLE);
					break;
				case 10:
					vh.tv_evaluate.setVisibility(View.VISIBLE);
					break;
				case 11:
					vh.tv_more.setVisibility(View.VISIBLE);
					break;

				case 15://拒收
					vh.tv_more.setVisibility(View.VISIBLE);
					vh.tv_evaluate.setVisibility(View.VISIBLE);
					vh.tv_pay.setVisibility(View.VISIBLE);
					break;
				case 16:
					vh.tv_evaluate.setVisibility(View.VISIBLE);
					vh.tv_pay.setVisibility(View.VISIBLE);
					break;
				case 17:
					vh.tv_pay.setVisibility(View.VISIBLE);
					vh.tv_more.setVisibility(View.VISIBLE);
					break;
				case 22:
					vh.tv_pay.setVisibility(View.VISIBLE);
				default:
					break;
			}
		}



		@Override
		public void onClick(View v) {
			Object tag = v.getTag(R.id.item_key_position);
			if (tag != null && tag instanceof Integer) {
				int position = (int) tag;
				flagPosition = position;
// 交货码，查看物流，取消订单，确认收货，支付， 详情
				switch (v.getId()) {
					case R.id.tv_code:
						showCodeDialog(list.get(position).getInspectCode());
						break;
					case R.id.tv_sure:
						if(isWindowLocked())
							return;
						else
							mHttpCheck(flagPosition);
						break;
					case R.id.tv_logistics:
						Intent logisticsInfo = new Intent(context, OrderLogisticsInfoActivity.class);
						logisticsInfo.putExtra("logisticsNo", list.get(position).getOrderId());
						context.startActivity(logisticsInfo);
						break;
					case R.id.tv_pay:
						Intent pay = new Intent(context, WXPayEntryActivity.class);
						pay.putExtra("payWay", 1);
						String orderId = list.get(position).getOrderId();
						pay.putExtra("orderId",orderId);
						context.startActivity(pay);
						break;
					case R.id.tv_cancel:
						showCancelDialog();
						break;
					case R.id.tv_order_not_want:
						dialog.dismiss();
						mHttpCancel(list.get(flagPosition).getOrderId(),"不想要了");
						break;
					case R.id.tv_order_wrong:
						dialog.dismiss();
						mHttpCancel(list.get(flagPosition).getOrderId(),"点错了");
						break;
					case R.id.v_order_cancel:
						dialog.dismiss();
						break;
					case R.id.tv_more:
						if(isWindowLocked())
							return;
						else
							mHttpMore(flagPosition);
						break;
					case R.id.tv_evaluate:
						Intent evaluate = new Intent(context, EvaluateActivity.class);
						evaluate.putExtra("orderId",list.get(flagPosition).getOrderId());
						startActivityForResult(evaluate,0x001);
						break;
					case R.id.ll_order:
					case R.id.rl_more:
					case R.id.ll_images:
						Intent detail = new Intent(context,H5OrderDetailActivity.class);
						detail.putExtra("orderId", list.get(position).getOrderId());
						detail.putExtra(Constant.KEY_WEB_URL, "http://m.epfresh.com/help/order_detail.html?orderId="+list.get(position).getOrderId());
						detail.putExtra(Constant.KEY_WEB_TITLE, "订单详情");
						detail.putExtra("page",type);
						//((MyOrderActivity)context).startActivityForResult(detail,0x001);
						startActivityForResult(detail,0x001);

						break;
				}
			}
		}

		private Dialog dialogCancel;
		TextView[] numbers = new TextView[6];
		void showCodeDialog(String code){
			if (dialogCancel == null) {
				View view = LayoutInflater.from(context).inflate(R.layout.dialog_code, null);
				dialogCancel = new Dialog(context, R.style.ActionSheetDialogStyle);
				dialogCancel.setContentView(view);
				Window dialogWindow = dialogCancel.getWindow();
				dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
				WindowManager.LayoutParams lp = dialogWindow.getAttributes();
				lp.width = LocalDisplay.SCREEN_WIDTH_PIXELS;
				dialogWindow.setAttributes(lp);
				numbers[0] = (TextView)view.findViewById(R.id.number1);
				numbers[1] = (TextView)view.findViewById(R.id.number2);
				numbers[2] = (TextView)view.findViewById(R.id.number3);
				numbers[3] = (TextView)view.findViewById(R.id.number4);
				numbers[4] = (TextView)view.findViewById(R.id.number5);
				numbers[5] = (TextView)view.findViewById(R.id.number6);
			}
			for(int i=0;i<6;i++){
				numbers[i].setText(""+code.charAt(i));
			}
			dialogCancel.show();
		}

		private Dialog dialog;
		private int flagPosition;
		View view,v_order_cancel,tv_order_not_want,tv_order_wrong;
		public void showCancelDialog() {
			if (dialog == null) {
				view = LayoutInflater.from(context).inflate(R.layout.dialog_order, null);
				v_order_cancel = view.findViewById(R.id.v_order_cancel);
				tv_order_not_want = view.findViewById(R.id.tv_order_not_want);
				tv_order_wrong = view.findViewById(R.id.tv_order_wrong);
				v_order_cancel.setOnClickListener(this);
				tv_order_wrong.setOnClickListener(this);
				tv_order_not_want.setOnClickListener(this);
				dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
				dialog.setContentView(view);
				Window dialogWindow = dialog.getWindow();
				dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
				WindowManager.LayoutParams lp = dialogWindow.getAttributes();
				lp.width = LocalDisplay.SCREEN_WIDTH_PIXELS;
				dialogWindow.setAttributes(lp);
			}
			tv_order_wrong.setTag(R.id.item_key_position, flagPosition);
			v_order_cancel.setTag(R.id.item_key_position, flagPosition);
			tv_order_not_want.setTag(R.id.item_key_position, flagPosition);
			dialog.show();
		}
		*//** 取消订单 *//*
		private void mHttpCancel(String  id,String reason) {
			Log.i("列表测试", "" + id + reason);
			RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
			data.setCmd("appOrder/appCancelOrder");
			Map<String, Object> map = new HashMap<>();
			map.put("orderId", id);
			map.put("reason", reason);
			data.setParameters(map);
			((BaseActivity)context).request(data, "appOrder/appCancelLogisticsOrder", new OnRequestListener<StatusEntity>() {
				@Override
				public StatusEntity jsonToObj(String responseStr) {
					return new Gson().fromJson(responseStr, StatusEntity.class);
				}

				@Override
				public void onFail(int failCode, Object arg, Object tag) {
					Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
				}

				@Override
				public void onResponseError(int failCode, Object arg, Object tag) {
					((BaseActivity) context).toast((arg == null ? "" : arg + ""));
				}

				@Override
				public void onStart(Object tag) {
				}

				@Override
				public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
					StatusEntity responseElement = response.getResponseElement();
					if (responseElement.isSuccess()) {
						refresh();
						T.toast("已取消");
					} else {
						T.toast("服务器出现小问题，请稍后再试");
					}
				}
			});
		}
		*//** 确认收货1 有无尾款 *//*
		class SureCheckBean {
			int type;
			double money;
		}
		private void mHttpCheck(final int id) {
			RequestEntityPurchase<Map<String, Object>> dataRequest = new RequestEntityPurchase<>();
			dataRequest.setCmd("appOrder/checkReceiveGood");

			Map<String, Object> map = new HashMap<>();
			map.put("orderId", this.list.get(id).getOrderId());
			dataRequest.setParameters(map);
			((BaseActivity)context).request(dataRequest, "appOrder/checkReceiveGood", new OnRequestListener<SureCheckBean>() {
				@Override
				public SureCheckBean jsonToObj(String responseStr) {
					return new Gson().fromJson(responseStr, SureCheckBean.class);
				}

				@Override
				public void onFail(int failCode, Object arg, Object tag) {
					((BaseActivity) context).hideProgressDialog();
					Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
				}

				@Override
				public void onResponseError(int failCode, Object arg, Object tag) {
					((BaseActivity) context).hideProgressDialog();
					T.toast((arg == null ? "" : arg + ""));
				}

				@Override
				public void onStart(Object tag) {
					((BaseActivity) context).showProgressDialog();
				}

				@Override
				public void onResponse(ResponseEntity<SureCheckBean> response, Object tag) {
					((BaseActivity) context).hideProgressDialog();
					final SureCheckBean responseElement = response.getResponseElement();
					AlertDialog.Builder builder = new AlertDialog.Builder(context);
					builder.setMessage("您已经收到货物，验货通过，清点无误！");//设置显示的内容
					if (responseElement.type == 1||responseElement.type == 2) {//0结束；1：收银台，2：有尾款
						builder.setMessage("您已经收到货物，验货通过，清点无误！" + "\n" + "去收银台付款：" + responseElement.money + "元。");
					}*//* else if (responseElement.type == 2) {
                    builder.setMessage("您已经收到货物，验货通过，清点无误！" + "\n" + "并且已经付清尾款：" + responseElement.money + "元。");
                }*//*
					builder.setTitle("确认收货表示：")
							.setPositiveButton("确定", new DialogInterface.OnClickListener() {//添加确定按钮
								@Override
								public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
									if(responseElement.type==1||responseElement.type==2){
										Intent pay = new Intent(context, WXPayEntryActivity.class);
										pay.putExtra("orderId",OrderAdapter.this.list.get(id).getOrderId());
										pay.putExtra("type","2");
										context.startActivity(pay);
										return;
									}else{
										mHttpSure(id, responseElement.type);
										return;
									}
								}
							}).setNegativeButton("取消", new DialogInterface.OnClickListener() {//添加返回按钮
						@Override
						public void onClick(DialogInterface dialog, int which) {//响应事件
							// TODO Auto-generated method stub
						}

					}).show();//在按键响应事件中显示此对话框

				}
			});
		}
		*//** 确认收货2 *//*
		private void mHttpSure(int id,int type1) {
			RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
			data.setCmd("appOrder/confirmReceiveGood");
			Map<String, Object> map = new HashMap<>();
			map.put("orderId", this.list.get(id).getOrderId());
			map.put("type", ""+type1);
			data.setParameters(map);
			((BaseActivity)context).request(data, "appOrder/confirmReceiveGood", new OnRequestListener<StatusEntity>() {
				@Override
				public StatusEntity jsonToObj(String responseStr) {
					return new Gson().fromJson(responseStr, StatusEntity.class);
				}

				@Override
				public void onFail(int failCode, Object arg, Object tag) {
					Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
				}

				@Override
				public void onResponseError(int failCode, Object arg, Object tag) {
					T.toast((arg == null ? "" : arg + ""));
				}

				@Override
				public void onStart(Object tag) {
				}

				@Override
				public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
					StatusEntity responseElement = response.getResponseElement();
					if (responseElement.isSuccess()) {
						refresh();
					} else {
						T.toast("服务器出现小问题，请稍后再试");
					}
				}
			});
		}

		*//** 再来一旦 *//*
		private void mHttpMore(int id) {
			RequestEntityPurchase<Map<String, Object>> data = new RequestEntityPurchase<>();
			data.setCmd("appOrder/addToShoppingCarAgain");
			Map<String, Object> map = new HashMap<>();
			map.put("orderId", list.get(id).getOrderId());
			map.put("accountId",ApplicationHelper.getInstance().getUser().getAccountId());
			map.put("cityId", ApplicationHelper.getInstance().getCity().getCityId());
			data.setParameters(map);
			((BaseActivity)context).request(data, "appOrder/addToShoppingCarAgain", new OnRequestListener<StatusEntity>() {
				@Override
				public StatusEntity jsonToObj(String responseStr) {
					return new Gson().fromJson(responseStr, StatusEntity.class);
				}

				@Override
				public void onFail(int failCode, Object arg, Object tag) {
					((BaseActivity) context).hideProgressDialog();
					Toast.makeText(context, "服务器开小差了……", Toast.LENGTH_SHORT).show();
				}

				@Override
				public void onResponseError(int failCode, Object arg, Object tag) {
					((BaseActivity) context).hideProgressDialog();
					T.toast((arg == null ? "" : arg + ""));
				}

				@Override
				public void onStart(Object tag) {
					((BaseActivity) context).showProgressDialog();
				}

				@Override
				public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
					((BaseActivity) context).hideProgressDialog();
					Intent intent = new Intent(context,
							HomeActivity.class);
					intent.putExtra("home_tab_index", 2);
					DataManager.getInstance().isNeedRefreshCart = true;
					context.startActivity(intent);
					notifyDataSetChanged();
				}
			});
		}
		long mLastOnClickTime;
		public boolean isWindowLocked() {
			long current = SystemClock.elapsedRealtime();
			if(current - this.mLastOnClickTime > 1500L) {
				this.mLastOnClickTime = current;
				return false;
			} else {
				return true;
			}
		}
	}*/



}
